#ifndef GAMEWORLD_HPP_INCLUDED
#define GAMEWORLD_HPP_INCLUDED

#include "Consts.h"
#include "Unit.hpp"
#include "Player.h"
#include "Map.h"
#include "Drawing.h"
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#include <stdlib.h>
#include <map>
#include <cmath>

class GameWorld
{
private:
    std::map<short, Unit> m_units;
    Unit* m_selected_unit;
    sf::Vector2i m_hovered;
    int m_number_units;
    std::map<short,Player> m_players;
    Map m_map ;
    short m_current_turn ;

public:
    GameWorld( short map_size_x = 21 , short map_size_y = 21);

    void update(Drawing * drawingmodule, Player* player);

    void addUnit(Unit unit, sf::Vector2i pos);
    void removeUnit(short id);

    Unit* getUnit(short id);
    Unit* getUnit(int x, int y);

    int addPlayer(Player player);
    bool addPlayer(Player player,short id);
    void removePlayer(short id);

    Player* getPlayingPlayer(){return &m_players[m_current_turn] ;};
    Player* getPlayer(short id){return &m_players[id] ;};

    Map const & getMap() const {return m_map ;};

    void testCase(int i, int pos[2], std::vector< std::vector<int> >* square, Unit* unit);
    void showMove(Drawing * drawingmodule, Unit* unit, Player* player);
    int isInMoveRange(int x_m, int y_m, Unit* unit) const ;
    int moveUnit(int x_m, int y_m, Unit* unit);

    void changeTerrainAt(short x, short y, short newid) ;




    bool endTurn(Player * player);
    void newTurn(Player * player);

    int attackUnit(Unit* attacker, Unit* unit);
    //========== Selection pointer related functions
    Unit* select(int x, int y);
    void unselect();
    Unit* getCursorUnit(int x, int y) const;

    Unit* getSelected() { return m_selected_unit;};
    //==========


    // Hover related
    void hover(int x, int y);
    sf::Vector2i getHover() const { return m_hovered ;};
};

#endif // GAMEWORLD_HPP_INCLUDED
